package com.xuelang.pipeline.worker.client.common.feign;

import com.xuelang.pipeline.worker.client.common.result.ApiResult;
import com.xuelang.pipeline.worker.client.deployment.IDeploymentService;
import com.xuelang.pipeline.worker.client.deployment.dto.DeployQueryDTO;
import io.kubernetes.client.openapi.models.V1DeploymentList;
import io.kubernetes.client.openapi.models.V1Scale;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * @author liuyuan.ly
 * @since 2024/8/8 16:56
 */
@Slf4j
@Component
public class DeploymentServiceFallbackImpl implements IDeploymentService {
    private final String fallReason = "服务降级：远程服务不可用";

    @Override
    public ApiResult<V1DeploymentList> getDeploymentList(DeployQueryDTO queryDTO) {
        log.error("[Fallback] getDeploymentList fallback. reason: {}", fallReason);
        return ApiResult.<V1DeploymentList>failT(fallReason);
    }

    @Override
    public ApiResult<V1Scale> patchDeployment(DeployQueryDTO queryDTO) {
        log.error("[Fallback] patchDeployment fallback. reason: {}", fallReason);
        return ApiResult.<V1Scale>failT(fallReason);
    }

    @Override
    public ApiResult<List<String>> listAvailableDeploymentName(DeployQueryDTO queryDTO) {
        log.error("[Fallback] listAvailableDeploymentName fallback. reason: {}", fallReason);
        return ApiResult.<List<String>>failT(fallReason);
    }
}
